<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/14
 * Time: 17:39
 */
namespace App\Http\Controllers\Api\V1_9_3;

use App\Http\Requests\Api\V1_9_3\RepaymentAccountWithdrawRequest;
use App\Services\InvitedService;
use App\Services\RepaymentAccountWithdrawService;
use Illuminate\Http\Request;

class InvitedController extends BaseController
{
    protected $invitedService;

    public function __construct(InvitedService $invitedService)
    {
        parent::__construct();
        $this->invitedService = $invitedService;
    }

    /**
     * 邀请人数统计
     */
    public function invitedNumber()
    {
        return $this->invitedService->invitedNumber($this->user['user_id']);
    }

    /**
     * 直接的被邀请人列表
     */
    public function directBeInvited(Request $request)
    {
        if (empty($request->level)) {
            $level = 0;
        } else {
            $level = json_decode($request->level);
            if (!is_array($level)) {
                return $this->responseJson(422);
            }
        }
        return $this->invitedService->directBeInvited($this->user['user_id'], $level, $request->page);
    }

    /**
     * 直接被邀请人详情
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function directBeInvitedDetail(Request $request)
    {
        if (empty($request->id)) {
            return $this->responseJson(422);
        }
        return $this->invitedService->directBeInvitedDetail($request->id, $this->user['user_id']);
    }
}